﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Panny.Data;
using System.ComponentModel;
using Entity;
namespace Controller
{
    [DataObject()]
   public class CorpInfoShow
   {
        [DataObjectMethod(DataObjectMethodType.Select)]
        public DataSet Get_er_indexTopCorpInfo(string typeid,string areaid)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append(" select top 1 Title,username,CorpID, Summary,Address,");
            sql.Append(" (select top 1 a.VidioURL from CorpVideo a where a.CorpID=CorpInfo.CorpID order by a.Sort desc,a.Hits ) as VidioURL ");
            sql.Append(" from CorpInfo ");
            sql.AppendFormat(" where ('{0}'='0' or typeid = '{0}') ", typeid);
            sql.AppendFormat(" and ('{0}'='0' or areaID = '{0}') ", areaid);
            sql.Append(" order by Hits desc,CreateOn desc");
            using (SqlText selection = new SqlText(sql.ToString()))
            {
                return selection.GetDataset();
            }
        }

       #region /index.aspx 页面 


       /// <summary>
       /// /index.aspx 页面 默认商户视频
       /// </summary>
       /// <param name="corpID"></param>
       /// <returns></returns>
        [DataObjectMethod(DataObjectMethodType.Select)]
       public DataSet GetIndexCorpInfo(string corpID)
       {
           StringBuilder sql = new StringBuilder();
           sql.Append(" select top 1 Title,username,CorpID, Summary,");
           sql.Append(" (select top 1 a.VidioURL from CorpVideo a where a.CorpID=CorpInfo.CorpID order by a.Sort desc,a.Hits ) as VidioURL ");
           sql.Append(" from CorpInfo ");
           if(!string.IsNullOrEmpty(corpID))
               sql.AppendFormat(" where corpid = '{0}' ",corpID);
           sql.Append(" order by VidioURL desc,Sort desc,CreateOn desc");
           using (SqlText selection = new SqlText(sql.ToString()))
           {
              return selection.GetDataset();
           }
       }



       /// <summary>
       /// 获取最新的
       /// </summary>
       /// <param name="tops">top number</param>
       /// <param name="areaID">city id</param>
       /// <param name="inType">hot,new,good</param>
       /// <returns></returns>
        [DataObjectMethod(DataObjectMethodType.Select)]
       public DataSet GetIndexMore(int tops,string areaID,string inType)
       {
           if(tops<=0)
               tops=10;
           StringBuilder sql = new StringBuilder();
           sql.AppendFormat("select top {0} TypeID,Title,CorpID,Hits,ImageSrc,Keys,Address from CorpInfo where areaID = @AreaID ", tops);
           switch (inType)
           {
               case "hot":
                   sql.Append(" order by Hits desc,Sort desc,Createon desc ");
                   break;
               case "new":
                   sql.Append(" order by Convert(varchar(10),CreateOn,126) desc,Sort desc,Hits desc ");
                   break;
               case "good":
                   sql.Append(" order by Sort desc,Hits desc ");
                   break;
               default :
                   sql.Append(" order by Sort desc,Hits desc ");
                   break;
           }
           using (SqlText selection = new SqlText(sql.ToString()))
           {
               selection.AddParameter("@AreaID", areaID);
               return selection.GetDataset();
           }
       }

        public DataSet GetIndexDiffType()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append(" select top 50 corpid,title,b.AreaName as cityname,imagesrc,typeid,corpinfo.sort");
            sql.Append("  from corpinfo left join sys_area as b on b.areaid=corpinfo.AreaID ");
            sql.Append("  where typeid in (1,2,5) and imagesrc is not null order BY Hits desc,Convert(VARCHAR(10),createon,126) desc ");
            using (SqlText selection = new SqlText(sql.ToString()))
            {
                return selection.GetDataset();
            }
        }


        public DataSet GetIndexMore(string areaID)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select TypeID,Title,CorpID,Hits,ImageSrc,Keys,Sort,CreateOn,Address from CorpInfo where areaID = @AreaID ");
            using (SqlText selection = new SqlText(sql.ToString()))
            {
                selection.AddParameter("@AreaID", areaID);
                return selection.GetDataset();
            }
        }



       #endregion

       #region /corp/corpView.aspx 页面

       public CorpInfo GetCorpViewDetail(string cid)
        {
            CorpInfo info = new CorpInfo();
            using (SqlStoredProcedure selection = new SqlStoredProcedure("Pro_Pan_CorpInfo_GetDetail"))
            {
                selection.AddParameter("@CorpID", cid);
                while (selection.Read())
                {
                    info.CorpID =Convert.ToInt32(selection["CorpID"].ToString());
                    info.Title = selection["Title"].ToString();
                    info.AreaID =Convert.ToInt32(selection["AreaID"].ToString());
                    info.TypeID = Convert.ToInt32(selection["TypeID"].ToString());
                    info.UserName = selection["UserName"].ToString();
                    info.WorkTime = selection["WorkTime"].ToString();
                    info.Address = selection["Address"].ToString();
                    info.BusLine = selection["BusLine"].ToString();
                    info.Consume = selection["Consume"].ToString();
                    info.Fax = selection["Fax"].ToString();
                    info.Hits = Convert.ToInt32(selection["Hits"].ToString());
                    info.ImageSrc = selection["ImageSrc"].ToString();
                    info.Keys = selection["Keys"].ToString();
                    info.MapLocation = selection["MapLocation"].ToString();
                    info.MarkName = selection["MarkName"].ToString();
                    info.Remark = selection["Remark"].ToString();
                    info.Site = selection["Site"].ToString();
                    info.Summary = selection["Summary"].ToString();
                    info.Telphone = selection["Telphone"].ToString();
                }
                 
            }
            return info;
        }


       #endregion 
       #region article.aspx

       public DataSet GetArticleDiffType(string areaid)
       {
           StringBuilder sql = new StringBuilder();
           sql.Append(" select top 10 corpid,title,b.AreaName as cityname,imagesrc,typeid,corpinfo.sort,corpinfo.hits");
           sql.Append("  from corpinfo left join sys_area as b on b.areaid=corpinfo.AreaID ");
           sql.Append("  where typeid in (1,2,5) and imagesrc is not null and corpinfo.AreaID=@AreaID order BY Sort desc,Hits desc,Convert(VARCHAR(10),createon,126) desc ");
           using (SqlText selection = new SqlText(sql.ToString()))
           {
               selection.AddParameter("@AreaID", areaid);
               return selection.GetDataset();
           }
       }

       #endregion

   }
}
